package com.ayf.payment.game.api.channel.ehb.response;

import com.alibaba.fastjson.annotation.JSONField;
import com.swwx.charm.commons.lang.base.BasicTO;
import org.apache.commons.lang3.StringUtils;

public class BaseRes extends BasicTO {

    private static final long serialVersionUID = 1L;

    @JSONField(name = "return_code")
    private ResReturnCodeEnum returnCode;
    @JSONField(name = "return_msg")
    private String returnMsg;
    @JSONField(name = "err_code")
    private String errCode;
    @JSONField(name = "err_code_desc")
    private String errCodeDesc;
    @JSONField(name = "encrypted_key")
    private String encryptedKey;

    /**
     * 接口响应是否成功
     */
    public boolean reqSuccessFlag;
    /**
     * 业务处理是否成功
     */
    private boolean isSuccess;

    /**
     * 失败原因
     */
    private String failRason;

    public ResReturnCodeEnum getReturnCode() {
        return returnCode;
    }

    public void setReturnCode(ResReturnCodeEnum returnCode) {
        this.returnCode = returnCode;
    }

    public String getReturnMsg() {
        return returnMsg;
    }

    public void setReturnMsg(String returnMsg) {
        this.returnMsg = returnMsg;
    }

    public String getErrCode() {
        return errCode;
    }

    public void setErrCode(String errCode) {
        this.errCode = errCode;
    }

    public String getErrCodeDesc() {
        return errCodeDesc;
    }

    public void setErrCodeDesc(String errCodeDesc) {
        this.errCodeDesc = errCodeDesc;
    }

    public String getEncryptedKey() {
        return encryptedKey;
    }

    public void setEncryptedKey(String encryptedKey) {
        this.encryptedKey = encryptedKey;
    }

    public boolean isReqSuccessFlag() {
        return reqSuccessFlag;
    }

    public void setReqSuccessFlag(boolean reqSuccessFlag) {
        this.reqSuccessFlag = reqSuccessFlag;
    }

    public boolean isSuccess() {
        if (ResReturnCodeEnum.SUCCESS.equals(returnCode) &&
                (ResReturnCodeEnum.SUCCESS.name().equals(errCode) || ResReturnCodeEnum.PROCESSING.name().equals(errCode))){
            return true;
        }
        return false;
    }

    public String getFailRason() {
        if (!isSuccess) {
            return StringUtils.isEmpty(errCodeDesc)?returnMsg:errCodeDesc;
        }
        return "";
    }
}
